package com.awei.study.design.structure.decorator;

/**
 * @Author liweilong
 * @Date 2024/8/7 21:22
 * 装饰者
 */
public class Decorator {
    public static abstract class FastFood {
        private Float price;
        private String desc;

        public FastFood(Float price, String desc) {
            this.price = price;
            this.desc = desc;
        }

        public Float getPrice() {
            return price;
        }

        public void setPrice(Float price) {
            this.price = price;
        }

        public String getDesc() {
            return desc;
        }

        public void setDesc(String desc) {
            this.desc = desc;
        }

        public abstract Float cost();
    }

    public class FireRice extends FastFood {

        public FireRice(Float price, String desc) {
            super(price, desc);
        }

        @Override
        public Float cost() {
            return getPrice();
        }
    }

    public static class FireNoodle extends FastFood {

        public FireNoodle(Float price, String desc) {
            super(price, desc);
        }

        @Override
        public Float cost() {
            return getPrice();
        }
    }

    public static abstract class FoodAdapter extends FastFood {

        private FastFood fastFood;

        public FoodAdapter(FastFood fastFood,Float price, String desc) {
            super(price, desc);
            this.fastFood = fastFood;
        }

        public FastFood getFastFood() {
            return fastFood;
        }

        public void setFastFood(FastFood fastFood) {
            this.fastFood = fastFood;
        }
    }

    public static class AddEgg extends FoodAdapter {

        public AddEgg(FastFood fastFood, Float price, String desc) {
            super(fastFood, price, desc);
        }

        @Override
        public Float cost() {
            return super.getPrice() + getFastFood().getPrice();
        }

        @Override
        public String getDesc() {
            return super.getDesc() + getFastFood().getDesc();
        }
    }

    public static class AddMeat extends FoodAdapter {

        public AddMeat(FastFood fastFood, Float price, String desc) {
            super(fastFood, price, desc);
        }

        @Override
        public Float cost() {
            return super.getPrice() + getFastFood().getPrice();
        }

        @Override
        public String getDesc() {
            return super.getDesc() + getFastFood().getDesc();
        }
    }

    public static void main(String[] args) {

        FastFood fireNoodle = new FireNoodle(10f,"面条");
        AddEgg addEgg = new AddEgg(fireNoodle,2f,"鸡蛋");
        System.out.println(addEgg.getDesc() +addEgg.cost());
        AddMeat addMeat = new AddMeat(fireNoodle,3f,"肉");
        System.out.println(addMeat.getDesc() + addMeat.cost());
    }
}
